<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="path" value="${pageContext.request.contextPath}" />

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>注册 - layuiAdmin</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="layui/css/layui.css" media="all">
  <link rel="stylesheet" href="layui/admin.css" media="all">
  <link rel="stylesheet" href="layui/login.css" media="all">
</head>
<body>
  <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
    <div class="layadmin-user-login-main">
      <div class="layadmin-user-login-box layadmin-user-login-header">
        <h2>Library空间管理系统</h2>
        <p>不再因座位发愁</p>
      </div>
      <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
              <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-nickname"></label>
          <input type="text" name="name" id="LAY-user-login-nickname" lay-verify="nickname" placeholder="昵称" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="LAY-user-login-cellphone"></label>
          <input type="text" name="uname" id="LAY-user-login-name" lay-verify="phone" placeholder="学号" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
          <input type="password" name="passwd" id="LAY-user-login-password" lay-verify="pass" placeholder="密码" class="layui-input">
        </div>
        <div class="layui-form-item">
          <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
          <input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码" class="layui-input">
        </div>
        <div class="layui-form-item layui-hide" >
			<label class="layui-form-label required">日期</label>
			<div class="layui-input-block">
				<input type="text" id="ctime" name="ctime" value="${student.ctime}"  class="layui-input" disabled="disabled"/>
			</div>
		</div>	
        <div class="layui-form-item">
   			 <label class="layui-form-label">性别</label>
  			 <div class="layui-input-block">
     			 <input type="radio" name="sex" value="1" title="男" checked>
     			 <input type="radio" name="sex" value="0" title="女" >
   			 </div>
  		</div>
  		
        <div class="layui-form-item">
          <input type="checkbox" name="agreement" lay-skin="primary" title="同意用户协议" checked>
        </div>
        <div class="layui-form-item">
          <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-reg-submit">注 册</button>
        </div>
        <div class="layui-trans layui-form-item layadmin-user-login-other">
          <label>社交账号注册</label>
          <a href="javascript:;"><i class="layui-icon layui-icon-login-qq"></i></a>
          <a href="javascript:;"><i class="layui-icon layui-icon-login-wechat"></i></a>
          <a href="javascript:;"><i class="layui-icon layui-icon-login-weibo"></i></a>         
          <a href="${path}/login.jsp" class="layadmin-user-jump-change layadmin-link layui-hide-xs">用已有帐号登入</a>
        </div>
      </div>
    </div> 
  </div>

  <script src="layui/layui.js"></script>  
  <script>
  layui.config({
   	 base: 'layui/' //静态资源所在路径
	  }).extend({
   	 index: 'lib/index' //主入口模块
  	}).use(['index', 'user'], function(){
  	  var $ = layui.$
   	 ,setter = layui.setter
   	 ,admin = layui.admin
   	 ,form = layui.form
   	 ,router = layui.router();
    form.render();

    //提交
    form.on('submit(LAY-user-reg-submit)', function(obj){
      var field = obj.field;
      
      //确认密码
      if(field.passwd !== field.repass){
        return layer.msg('两次密码输入不一致');
      }
      
      //是否同意用户协议
      if(!field.agreement){
        return layer.msg('你必须同意用户协议才能注册');
      }
      
      //请求接口
      admin.req({
        url: '${path}/action/student/save' //实际使用请改成服务端真实接口
        ,data: field
        ,done: function(res){        
          layer.msg('注册成功', {
            offset: '15px'
            ,icon: 1
            ,time: 1000
          }, function(){
            location.href ='${path}/login.jsp'; //跳转到登入页
          });
        }
      });
      return false;
    });
  });
  layui.use('laydate', function(){
	  var laydate = layui.laydate;
	  
	  //执行一个laydate实例
	  laydate.render({
			elem: '#ctime'
			,value: new Date() //当前时间
			,isInitValue:true
		});	
	});

  </script>
</body>
</html>